/**********************************************************************\
 © COPYRIGHT 2006 Corporation for National Research Initiatives (CNRI);
                        All rights reserved.
               
        The HANDLE.NET software is made available subject to the
         Handle System Public License, which may be obtained at
         http://hdl.handle.net/4263537/5030 or hdl:4263537/5030
\**********************************************************************/

package net.handle.apps.servlet_proxy.handlers;

import net.handle.hdllib.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import net.handle.apps.servlet_proxy.*;

public class Admin implements TypeHandler {

  /** 
  * Return true iff this TypeHandler can send a redirect to the client
  * based on the given set of HandleValues.
  */
  public boolean canRedirect(HandleValue values[]) {
    return false;
  }
  
  /** 
    * Return true iff this TypeHandler can and should be used to format the 
    * data from the given HandleValue for a human client.
    */
  public boolean canFormat(HandleValue value) {
    if(value==null) return false;
    return value.hasType(Common.ADMIN_TYPE);
  }
  
  public String toHTML(String handle, HandleValue value) {
    AdminRecord admin = new AdminRecord();
    try {
      Encoder.decodeAdminRecord(value.getData(), 0, admin);
      return admin.toString();
    } catch (HandleException e) {
      return "?!? - Broken Admin Value - ?!?";
    }
  }
  
  public boolean doRedirect(HttpServletRequest request, 
                            HttpServletResponse response, HttpParams params,
                            String handle, HandleValue values[]) {
    return false;
  }

}
